package com.zh.note.huawei.twohundred.能力组队or最多可以派出多少支团队;

import java.util.*;

/**
 * @Author: zhanghuan
 * @date: 2023/9/3 22:59
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // int n = scanner.nextInt();
        // String line = scanner.nextLine();
        // int target = scanner.nextInt();
        int n = 7;
        String line = "3 1 5 7 9 7 1";
        int target = 8;
        int[] nums = Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt).toArray();

        //去重
        // Set<Integer> unquieNumbers = new HashSet<>();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            // if (!unquieNumbers.contains(nums[i])) {
            //     unquieNumbers.add(nums[i]);
            list.add(nums[i]);
            // }
        }
        Collections.sort(list);
        int count = 0;
        int right = list.size() - 1;
        // 先把大于target的 先选出来
        while (right >= 0 && list.get(right) >= target) {
            count++;
            right--;
        }
        int left = 0;
        while (left < right) {
            if (list.get(left) + list.get(right) >= target) {
                count++;
                left++;
                right--;
            } else {
                left++;
            }
        }
        System.out.println(count);


    }
}
